package com.wing.user.feign;

import com.wing.common.utils.JsonResult;
import com.wing.common.utils.PageResult;
import com.wing.user.model.request.*;
import com.wing.user.model.response.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 调用用户中心中的userdetail对象，用户oauth中的登录
 * 获取的用户与页面输入的密码 进行BCryptPasswordEncoder匹配
 *
 * @author
 */
@Component
@FeignClient(name = "${user.appName}", fallback = UserClientFallback.class)
public interface UserClient {

    /**
     * 通过用户名或昵称找到用户
     *
     * @param name 用户名或昵称
     * @return {@link UserAuthVO}
     */
    @GetMapping(value = "/user/admin/user/getByName", params = "username")
    JsonResult<UserVO> findUserByName(@RequestParam("name") String name);

    /**
     * 通过用户名或手机号找到用户
     *
     * @param username 用户名或手机号
     * @return {@link UserAuthVO}
     */
    @GetMapping(value = "/user/admin/user/getByUsername", params = "username")
    JsonResult<UserAuthVO> findUserByUsername(@RequestParam("username") String username);

    /**
     * 通过手机号找到用户
     *
     * @param phone 手机号
     * @return {@link UserAuthVO}
     */
    @GetMapping(value = "/user/admin/user/getByPhone", params = "phone")
    JsonResult<UserAuthVO> findUserByPhone(@RequestParam("phone") Long phone);

    /**
     * 通过openId找到用户
     *
     * @param openId openId
     * @return {@link UserAuthVO}
     */
    @GetMapping(value = "/user/admin/user/getByOpenId", params = "openId")
    JsonResult<UserAuthVO> findUserByOpenId(@RequestParam("username") String openId);

    /**
     * 通过客户端id找到客户端
     *
     * @param clientId 客户端id
     * @return {@link ClientVO}
     */
    @GetMapping(value = "/user/admin/client/getByClientId", params = "clientId")
    JsonResult<ClientVO> findClientByClientId(@RequestParam("clientId") String clientId);

    /**
     * 权限列表
     *
     * @param authorityIds 授权id
     * @return {@link List<AuthorityVO>}
     */
    @GetMapping(value = "/user/admin/authority/listByIds", params = "authorityIds")
    JsonResult<Collection<AuthorityVO>> authorityList(@RequestParam("authorityIds") String authorityIds);


    /**
     * 刷新redis权限缓存列表
     *
     * @return {@link JsonResult}
     */
    @GetMapping(value = "/user/admin/authority/authorityRoleList")
    JsonResult<List<RoleAuthorityVO>> authorityRoleList();

    /**
     * 更新用户状态
     *
     * @param userId 用户id
     * @param status 状态
     * @return {@link JsonResult}
     */
    @PutMapping("/user/admin/user/updateStatus")
    JsonResult updateStatus(@RequestParam("userId") Long userId, @RequestParam("status") Integer status);

    @GetMapping(value = "/user/admin/user/getUserInfo")
    JsonResult<UserVO> getUserInfo(@RequestParam("id") Long id);

    /**
     * 查询所有用户
     *
     * @return
     */
    @GetMapping(value = "/user/admin/user/getAll")
    JsonResult<List<UserVO>> getAll();

    /**
     *
     */
    @GetMapping(value = "/user/admin/department/list")
    JsonResult<PageResult<DepartmentVO>> getDepartment();

    /**
     * 根据id 查询企业
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/user/admin/companyInfo/getCompanyInfo")
    JsonResult<CompanyInfoVO> getCompanyInfo(@RequestParam("id") Long id);


    /**
     * 根据id 查询企业
     *
     * @param
     * @return
     */
    @GetMapping(value = "/user/admin/companyInfo/getCompanyInfoList")
    JsonResult<List<CompanyInfoVO>> getCompanyInfoList();


    /**
     * 通过ids查询角色岗位数据
     */
    @PostMapping(value = "/user/admin/role/getRoleData")
    JsonResult<List<RoleDataVo>> getRoleData(@RequestBody List<Long> ids);

    /**
     * 查询所有的部门
     */
    @GetMapping(value = "/user/admin/role/getRoleDepartment")
    List<Role> getRoleDepartment();

    /**
     * 根据id菜单信息
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/user/admin/menu/getMenuInfo")
    JsonResult<MenuVO> getMenuById(@RequestParam("id") Long id);

    @GetMapping(value = "/user/admin/user/getUserInfoByUserId")
    JsonResult<UserVO> getUserInfoByUserId(@RequestParam("userId") Long userId);

    /**
     * 添加应用授权信息
     */
    @PostMapping(value = "/user/admin/applicationAuth/add")
    JsonResult addApplicationAuth(@RequestBody ApplicationAuthForm applicationAuthForm);

    /**
     * 修改应用授权信息
     */
    @PostMapping(value = "/user/admin/applicationAuth/update")
    JsonResult updateApplicationAuth(@RequestBody ApplicationAuthForm applicationAuthForm);

    /**
     * 查询应用授权信息
     *
     * @param appId
     * @return
     */
    @GetMapping(value = "/user/admin/applicationAuth/getApplicationAuthByAppId")
    JsonResult<ApplicationAuthVO> getApplicationAuthByAppId(@RequestParam("appId") String appId);

    /**
     * 查询部门信息
     *
     * @param departmentId
     * @return
     */
    @GetMapping(value = "/user/admin/department/getDepartmentVOById")
    JsonResult<DepartmentVO> getDepartmentVOById(@RequestParam(name = "departmentId") Long departmentId);

    @GetMapping(value = "/user/admin/department/getDepartmentList")
    JsonResult<List<DepartmentVO>> getDepartmentList();

    /**
     * 根据名称 查询企业
     *
     * @param companyName
     * @return
     */
    @GetMapping(value = "/user/admin/companyInfo/getCompanyInfoByName")
    JsonResult<CompanyInfoVO> getCompanyByName(@RequestParam("name") String companyName);

    /**
     * 查询部门信息
     *
     * @param name
     * @return
     */
    @GetMapping(value = "/user/admin/department/getDepartmentByName")
    JsonResult<DepartmentVO> getDepartmentByName(@RequestParam(name = "name", required = false) String name
            , @RequestParam(name = "thirdPartyDepartmentId", required = false) Long thirdPartyDepartmentId
            , @RequestParam(name = "companyInfoId", required = false) Long companyInfoId);

    /**
     * 校验部门编号
     *
     * @param code
     * @return
     */
    @GetMapping(value = "/user/admin/department/isOnly")
    JsonResult isOnly(@RequestParam(name = "code", required = false) String code,
                      @RequestParam(name = "id", required = false) Long id);

    /**
     * 校验部门名称
     *
     * @param name
     * @return
     */
    @GetMapping("/user/admin/department/isOnlyName")
    JsonResult isOnlyName(@RequestParam(name = "name", required = false) String name,
                          @RequestParam(name = "id", required = false) Long id,
                          @RequestParam(name = "companyInfoId", required = false) Long companyInfoId);

    /**
     * 添加部门
     *
     * @param departmentForm
     * @return
     */
    @PostMapping("/user/admin/department/addDepartment")
    JsonResult addDepartment(@RequestBody DepartmentForm departmentForm);

    @PutMapping("/user/admin/department/updateDepartment")
    JsonResult updateDepartment(@RequestBody DepartmentForm departmentForm);


    /**
     * 校验角色编号唯一性
     *
     * @param code
     * @param id
     * @return
     */
    @GetMapping("/user/admin/role/isOnly")
    JsonResult roleIsOnly(@RequestParam(name = "code", required = false) String code,
                          @RequestParam(name = "id", required = false) Long id);

    /**
     * 校验角色名称唯一性
     *
     * @param name
     * @param id
     * @param companyInfoId
     * @param departmentId
     * @return
     */
    @GetMapping("/user/admin/role/isOnlyName")
    JsonResult roleIsOnlyName(@RequestParam(name = "name", required = false) String name,
                              @RequestParam(name = "id", required = false) Long id,
                              @RequestParam(name = "companyInfoId", required = false) Long companyInfoId,
                              @RequestParam(name = "departmentId", required = false) Long departmentId);

    @PostMapping("/user/admin/role/roleAdd")
    JsonResult roleAdd(@RequestBody Role role);

    @PutMapping("/user/admin/role/updateRole")
    JsonResult updateRole(@RequestBody Role role);

    @GetMapping("/user/admin/role/getTreeData")
    JsonResult getTreeData(@RequestParam(name = "roleId", required = false) Long roleId,
                              @RequestParam(name = "companyInfoId", required = false) String companyInfoId );
    /**
     * 校验企业名称
     *
     * @param name
     * @param id
     * @return
     */
    @GetMapping("/user/admin/companyInfo/isOnlyName")
    JsonResult isOnlyCompanyName(@RequestParam(name = "name", required = false) String name,
                                 @RequestParam(name = "id", required = false) Long id);

    @PostMapping("/user/admin/companyInfo/addCompany")
    JsonResult addCompany(@RequestBody CompanyInfoForm companyInfoForm);

    /**
     * 根据岗位名称和部门id查询
     *
     * @param name
     * @param departmentId
     * @return
     */
    @GetMapping("/user/admin/role/getRoleInfoByName")
    JsonResult<Role> getRoleInfoByName(@RequestParam(name = "name", required = false) String name
            , @RequestParam(name = "departmentId", required = false) Long departmentId
            , @RequestParam(name = "thirdPartyJobtitleId", required = false) Long thirdPartyJobtitleId
            , @RequestParam(name = "companyInfoId", required = false) Long companyInfoId);

    /**
     * 校验用户工号，手机号的唯一
     *
     * @param username
     * @param phone
     * @param id
     * @return
     */
    @GetMapping("/user/admin/user/isOnly")
    JsonResult userIsOnly(@RequestParam(name = "username", required = false) String username,
                          @RequestParam(name = "phone", required = false) String phone,
                          @RequestParam(name = "id", required = false) Long id);

    /**
     * 添加用户
     *
     * @param user
     * @return
     */
    @PostMapping("/user/admin/user/addUser")
    JsonResult addUser(@RequestBody User user);

    /**
     * 修改用户
     *
     * @param user
     * @return
     */
    @PutMapping("/user/admin/user/updateUser")
    JsonResult updateUser(@RequestBody User user);

    @GetMapping("/user/admin/user/getUserByUserName")
    JsonResult<User> getUserByUserName(@RequestParam(name = "username") String username);

    @GetMapping("/user/admin/user/getUserInfoByUserName")
    JsonResult<UserVO> getUserInfoByUserName(@RequestParam(name = "username") String username);

    @GetMapping("/user/admin/user/passwordEncoder")
    JsonResult passwordEncoder(@RequestParam(name = "password") String password);

    /**
     * 对外开放的API接口列表(用户)
     *
     * @param page
     * @param limit
     * @param departmentId
     * @param postId
     * @param username
     * @param nickname
     * @param phone
     * @return
     */
    @GetMapping("/user/app/user/foreignUserListAll")
    public PageResult<User> foreignUserListAll(@RequestParam(name = "page") Integer page,
                                               @RequestParam(name = "limit") Integer limit,
                                               @RequestParam(name = "departmentId") Long departmentId,
                                               @RequestParam(name = "postId") Long postId,
                                               @RequestParam(name = "username") String username,
                                               @RequestParam(name = "nickname") String nickname,
                                               @RequestParam(name = "phone") String phone);

    /**
     * 对外开放的API接口详情(用户)
     *
     * @param id
     * @return
     */
    @GetMapping("/user/app/user/foreignUserDetail")
    public JsonResult foreignUserDetail(@RequestParam(name = "id") Long id);

    /**
     * 对外开放的API接口列表(角色)
     *
     * @param page
     * @param limit
     * @param departmentId
     * @param roleName
     * @return
     */
    @GetMapping("/user/app/user/foreignRoleListAll")
    public PageResult<Role> foreignRoleListAll(@RequestParam(name = "page") Integer page,
                                               @RequestParam(name = "limit") Integer limit,
                                               @RequestParam(name = "departmentId") Long departmentId,
                                               @RequestParam(name = "roleName") String roleName);

    /**
     * 对外开放的API接口详情(角色)
     *
     * @param id
     * @return
     */
    @GetMapping("/user/app/user/foreignRoleDetail")
    public JsonResult foreignRoleDetail(@RequestParam(name = "id") Long id);

    /**
     * 对外开放的API接口列表(部门)
     *
     * @param page
     * @param limit
     * @param name
     * @return
     */
    @GetMapping("/user/app/user/foreignDepartmentListAll")
    public PageResult<Department> foreignDepartmentListAll(@RequestParam(name = "page") Integer page,
                                                           @RequestParam(name = "limit") Integer limit,
                                                           @RequestParam(name = "name") String name);

    /**
     * 对外开放的API接口详情(部门)
     *
     * @param id
     * @return
     */
    @GetMapping("/user/app/user/foreignDepartmentDetail")
    public JsonResult foreignDepartmentDetail(@RequestParam(name = "id") Long id);

    /**
     * 对外开放的API接口列表(公司)
     *
     * @param page
     * @param limit
     * @param name
     * @return
     */
    @GetMapping("/user/app/user/foreignCompanyInfoListAll")
    public PageResult<CompanyInfo> foreignCompanyInfoListAll(@RequestParam(name = "page") Integer page,
                                                             @RequestParam(name = "limit") Integer limit,
                                                             @RequestParam(name = "name") String name);

    /**
     * 对外开放的API接口详情(公司)
     *
     * @param id
     * @return
     */
    @GetMapping("/user/app/user/foreignCompanyInfoDetail")
    public JsonResult foreignCompanyInfoDetail(@RequestParam(name = "id") Long id);


    /**
     * 查询所有的岗位部门信息
     *
     * @return
     */
    @GetMapping("/user/admin/role/getRoleAllMap")
    public JsonResult<List<Map<String, String>>> getRoleAllMap();


    /**
     * 添加第三方用户
     *
     * @param user
     * @return
     */
    @PostMapping("/user/admin/user/addThirdUser")
    public JsonResult addThirdUser(@RequestBody User user);

    /**
     * 修改第三方用户
     *
     * @param user
     * @return
     */
    @PutMapping("/user/admin/user/updateThirdUser")
    public JsonResult updateThirdUser(@RequestBody User user);

    /**
     * 删除第三方用户
     *
     * @param username
     * @return
     */
    @GetMapping("/user/admin/user/delThirdUser")
    public JsonResult delThirdUser(@RequestParam(name = "username") String username);

    @PostMapping("/user/admin/systemDingTalkInfo/addOrUpdate")
    public JsonResult addOrUpdateDingTalkInfo(@RequestBody SystemDingTalkInfoForm user);


    @GetMapping("/user/admin/systemDingTalkInfo/list")
    public PageResult<SystemDingTalkInfo> getDingTalkInfoList(@RequestParam(name = "page") Integer page,
                                          @RequestParam(name = "limit") Integer limit);

    /**
     * 同步钉钉用户信息到本地系统
     * @return
     */
    @GetMapping("/user/admin/user/syncDingUserToSysUer")
    public JsonResult syncDingUserToSysUer();


    /**
     * 同步钉钉部门信息到本地系统
     * @return
     */
    @GetMapping("/user/admin/role/syncDingDeptToSysRole")
    public JsonResult syncDingDeptToSysRole();


    /**
     * 获取钉钉配置信息
     * @return
     */
    @GetMapping("/user/admin/user/getUserDingConfigInfo")
    public SystemDingTalkInfo getUserDingConfigInfo();

    /**
     * 获取钉钉用户信息
     * @return
     */
    @GetMapping("/user/admin/user/selUserDingInfo")
    public List<User> selUserDingInfo();


    /**
     * 查询部门下的直属人员信息
     * @return
     */
    @GetMapping("/user/admin/user/getBy/{departmentId}")
    public List<User> getByDepartmentId(@PathVariable(name = "departmentId") Long departmentId);

    @GetMapping("/user/admin/role/getAll")
    JsonResult<List<Role>> getAllRole();

    @GetMapping("/user/admin/role/listAll2")
    JsonResult<List<Role>> listAllRole(@RequestParam("name") String name);

    @GetMapping("/user/admin/role/get")
    JsonResult<Role> getRoleById(@RequestParam("id") Long id);

}
